import { ecs } from "db://oops-framework/libs/ecs/ECS";
import { Role } from "../../../role/Role";
import { Skill } from "../../skill/Skill";
import { RoleNumericDecorator } from "../../../role/model/attribute/RoleNumericDecorator";
import { TableBuff } from "../../../common/table/TableBuff";
import { BuffCls } from "../bll/content/BuffCastingCls";
import { RoleBuff } from "../../skill/bll/utils/RoleBuff";
import { BuffCasting } from "../bll/content/BuffCasting";

/** 持续状态效果（技能标号与效果属性类型形成唯一BUFF标识）（标识相同的BUFF择优覆盖） */
@ecs.register('BuffModel')
export class BuffModelComp extends ecs.Comp {
    get id(): number {
        return this.table.id;
    }
    set id(value: number) {
        if (this.table == null) this.table = new TableBuff();
        this.table.init(value);

        // BUFF效果计算组件
        var clsNum = BuffCls[value];
        if (clsNum)
            this.casting = new clsNum();
        else {
            console.error(`没找到找编号为【${value}】的BUFF逻辑组件`);
        }
    }


    /** 不能技能不同等级BUFF的唯一标识 */
    get key(): string {
        return RoleBuff.getKey(this.id, this.skill);
    }

    /** BUFF数据库 */
    table: TableBuff = null!;

    /** 技能表的buff数据 */
    config: any = null!;
    /** BUFF施放流程 */
    casting: BuffCasting = null!;
    /** 是否为永久生效 */
    forever: boolean = false;
    /** 持续回合 */
    round: number = 0;
    /** 叠加层数当前值 */
    overlying: number = 0;
    /** BUFF 释放者（用于日志） */
    caster: Role = null!;
    /** BUFF 受击者 */
    target: Role = null!;
    /** 施放BUFF的技能 */
    skill: Skill = null!;
    /** 持续生效的BUFF效果 */
    effects: RoleNumericDecorator[] = [];

    reset(): void {
        this.forever = false;
        this.round = 0;
        this.overlying = 0;
        this.caster = null!;
        this.target = null!;
        this.skill = null!;
        this.effects.splice(0, this.effects.length);
    }
}